#!/bin/bash

echo "🧪 测试ARM64架构的node-sass修复..."

# 创建测试项目目录
mkdir -p test-arm64-project
cd test-arm64-project

# 创建package.json
cat > package.json << 'EOF'
{
  "name": "test-arm64-project",
  "version": "1.0.0",
  "scripts": {
    "build:mp-weixin": "echo '构建微信小程序' && mkdir -p dist/build/mp-weixin && echo 'test' > dist/build/mp-weixin/test.js"
  },
  "dependencies": {
    "node-sass": "^4.14.1",
    "sass-loader": "^8.0.0"
  },
  "devDependencies": {
    "webpack": "^4.46.0"
  }
}
EOF

echo "✅ 创建了测试项目"
echo "🔧 构建ARM64兼容的Docker镜像..."
docker build --platform linux/amd64 -f ../Dockerfile.arm64-fix -t test-arm64-fix .

if [ $? -eq 0 ]; then
    echo "✅ Docker构建成功！"
    echo "🔍 进入容器验证..."
    docker run --platform linux/amd64 -it --rm test-arm64-fix sh -c "
        echo '验证node-sass安装:'
        node -e \"console.log('node-sass版本:', require('node-sass').info)\"
        echo ''
        echo '检查构建输出:'
        ls -la dist/build/mp-weixin/
    "
else
    echo "❌ Docker构建失败"
fi

# 清理
cd ..
rm -rf test-arm64-project
